<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        @keyframes clip {
            from {
                clip-path: circle(0% at var(--x) var(--y));
            }

            to {
                clip-path: circle(100% at var(--x) var(--y));
            }
        }

        .item {
            width: 100px;
            height: 100px;
            background-color: hsl(236, 56%, 42%);
            color: #fff;
            margin: 10px;
            text-align: center;
            line-height: 100px;
            clip-path: circle(50% at 50% 50%)
        }

        #list {
            height: 500px;
            width: 560px;
            display: flex;
            flex-wrap: wrap;
        }

        /* ::view-transition-old(root),
        ::view-transition-new(root) {
            animation-duration: .5s;
        } */

        .item {
            view-transition-name: var(--i);
        }

        .dark {
            color-scheme: dark;
        }

        ::view-transition-old(root) {
            animation: none;
        }

        ::view-transition-new(root) {
            mix-blend-mode: normal;
            animation: clip .5s ease-in;
        }
    </style>
</head>

<body>
    <button id="togglebtn">切换</button>
    <div class="list" id="list">
        <div class="item" style="--i: a1">1</div>
        <div class="item" style="--i: a2">2</div>
        <div class="item" style="--i: a3">3</div>
        <div class="item" style="--i: a4">4</div>
        <div class="item" style="--i: a5">5</div>
        <div class="item" style="--i: a6">6</div>
        <div class="item" style="--i: a7">7</div>
        <div class="item" style="--i: a8">8</div>
        <div class="item" style="--i: a9">9</div>
        <div class="item" style="--i: a10">10</div>
    </div>
    <script>
        console.log(document.documentElement);

        const list = document.getElementById('list')
        const btn = document.getElementById('togglebtn')

        // list.addEventListener('click', function (ev) {
        //     if (ev.target.className === 'item') {
        //         ev.target.remove()
        //     }
        // })

        btn.addEventListener('click', function (ev) {
            document.documentElement.style.setProperty('--x', ev.clientX + 'px')
            document.documentElement.style.setProperty('--y', ev.clientY + 'px')
            if (document.startViewTransition) {
                document.startViewTransition(() => {
                    document.documentElement.classList.toggle('dark')
                });
            } else {
                document.documentElement.classList.toggle('dark')
            }
        })
        list.addEventListener('click', function (ev) {
            if (document.startViewTransition) { // 如果支持就视图变换
                document.startViewTransition(() => { // 开始视图变换
                    ev.target.remove()
                });
            } else { // 不支持就执行原来的逻辑
                ev.target.remove()
            }
        })
    </script>
</body>

</html>